import { IVec2Like } from "cc";
import { MathUtils } from "../MathUtils";

export interface ILikeV2 {
    x: number,
    y: number
}
export default class Vector2 {
    public x: number;
    public y: number;
    constructor(x?: number, y?: number) {
        if (x != undefined)
            this.x = MathUtils.fixNumber(x);
        if (y != undefined)
            this.y = MathUtils.fixNumber(y);
    }

    // /** 向量加 */
    // add(vector: Vector2) {
    //     return new Vector2(this.x + vector.x, this.y + vector.y);
    // }

    // /** 向量减 */
    // minus(vector: Vector2) {
    //     return new Vector2(this.x - vector.x, this.y - vector.y);
    // }

    // /** 向量点乘/内积/数量积（结果是一个标量） */
    // multiply(vector: Vector2) {
    //     return this.x * vector.x + this.y * vector.y;
    // }

    // /** 向量数乘（结果是一个向量） */
    // scale(scalar: number) {
    //     return new Vector2(this.x * scalar, this.y * scalar);
    // }

    /**
     * 乘法
     * @param vector1 
     * @param vector2 
     * @returns 
     */
    public static multiply(vector1: Vector2, vector2: Vector2) {
        return vector1.x * vector2.x + vector1.y * vector2.y;
    }

    /**
     * 乘法
     * @param scalar 
     * @param vector 
     * @returns 
     */
    public static multiply2(scalar: number, vector: Vector2) {
        return new Vector2(vector.x * scalar, vector.y * scalar);
    }

    /**
     * 除法
     * @param vector 
     * @param scalar 
     * @returns 
     */
    public static division(vector: Vector2, scalar: number) {
        return new Vector2(vector.x / scalar, vector.y / scalar);
    }

    /**
     * 减法
     * @param vector1 
     * @param vector2 
     */
    public static subtract(vector1: IVec2Like, vector2: IVec2Like) {
        return new Vector2(vector1.x - vector2.x, vector1.y - vector2.y)
    }

    /**
     * 加法
     * @param vector1 
     * @param vector2 
     */
    public static addition(vector1: IVec2Like, vector2: IVec2Like) {
        return new Vector2(vector1.x + vector2.x, vector1.y + vector2.y);
    }
}